package com.rainbow.controller;

import cn.hutool.core.lang.Console;
import com.rainbow.entity.response.Result;
import com.rainbow.expetion.MyException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * 全局异常处理
 *
 * @Author rainbow
 **/
@ControllerAdvice
public class ExceptionHandlerController {


    @ExceptionHandler
    @ResponseBody
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public <T> Result<T> exception(Exception e) {
        return Result.errorResult(e.getLocalizedMessage());
    }

    @ExceptionHandler(MyException.class)
    @ResponseBody
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public <T> Result<T> myException(MyException e) {
        return Result.errorResult(e.getMsg());
    }


}
